package org.sc.learn.server.auth.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.BatchSize;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;

/**
 * @author qianwx
 */
@Entity
@Table(name = "t_auth_role")
@Data
@EqualsAndHashCode
public class Role extends AbstractAuditingEntity {

  private static final long serialVersionUID = 63819300066968353L;

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long id;

  private String name;

  private String value;

  @JsonIgnore
  @ManyToMany(targetEntity = Authority.class, fetch = FetchType.EAGER)
  @BatchSize(size = 20)
  private Set<Authority> authorities = new HashSet<>();
}
